﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
 }
 <div class="layuimini-container">
     <div class="layuimini-main">
         <fieldset class="table-search-fieldset layui-hide" id="searchField">
             <div>
                 <form class="layui-form layui-form-pane">
                     <div class="layui-form-item">
                         <div class="layui-inline">
                             <label class="layui-form-label">关键字:</label>
                             <div class="layui-input-inline">
                                 <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input">
                             </div>
                         </div>
                         <div class="layui-inline">
                             <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                         </div>
                     </div>
                 </form>
             </div>
         </fieldset>
         <script type="text/html" id="toolbarDemo">
             <div class="layui-btn-container" id="toolbar">
                 <button id="NF-add" name="NF-add" authorize class="layui-btn layui-btn-sm data-add-btn" lay-event="add"><i class="layui-icon">&#xe654;</i>新增</button>
                 <button id="NF-edit" name="NF-edit" authorize class="layui-btn layui-btn-sm layui-btn-warm data-edit-btn layui-hide" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</button>
                 <button id="NF-delete" name="NF-delete" authorize class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                 <button id="NF-details" name="NF-details" authorize class="layui-btn layui-btn-sm layui-btn-normal data-info-btn layui-hide" lay-event="details"> <i class="layui-icon">&#xe60b;</i>查看</button>
                 <button id="NF-print" name="NF-print" authorize class="layui-btn layui-btn-sm layui-hide" lay-event="print"> <i class="layui-icon">&#xe66d;</i>打印</button>
                 <button id="NF-banding" name="NF-banding" authorize class="layui-btn layui-btn-sm data-banding-btn layui-hide" lay-event="banding"> <i class="fa fa-key"></i>区域绑定</button>
                 <button id="NF-materialbanding" name="NF-materialbanding" authorize="yes" class="layui-btn layui-btn-sm layui-btn-danger layui-hide" lay-event="materialbanding"> <i class="fa fa-hourglass-1"></i>物料绑定</button>

                 @*<button id="NF-user" name="NF-user" authorize class="layui-btn layui-btn-sm layui-btn-warm layui-hide" lay-event="user"> <i class="fa fa-user"></i>人员绑定</button>*@

             </div>
         </script>
         <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
         <script type="text/html" id="currentTableBar">
             <a id="NF-edit" authorize class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
             <a id="NF-delete" authorize class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"><i class="layui-icon">&#xe640;</i></a>
             <a id="NF-banding" authorize class="layui-btn layui-btn-sm data-banding-btn" lay-event="banding"><i class="fa fa-key"></i></a>
             <a id="NF-materialbanding" authorize class="layui-btn layui-btn-sm layui-btn-danger" lay-event="materialbanding"><i class="fa fa-hourglass-1"></i></a>
             @*<a id="NF-user" authorize class="layui-btn layui-btn-sm layui-btn-warm" lay-event="user"><i class="fa fa-user"></i></a>*@

         </script>
     </div>
 </div>
 <script>
     layui.use(['jquery', 'form', 'treeTable', 'common', 'optimizeSelectOption'], function () {
         var $ = layui.jquery,
             form = layui.form,
             treeTable = layui.treeTable,
             common = layui.common;
         //权限控制(js是值传递)
         currentTableBar.innerHTML = common.authorizeButtonNew(currentTableBar.innerHTML);
         toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
         var queryJson;
         var rendertree = common.rendertreetable({
             elem: '#currentTableId',
             treeIdName: 'F_Id',
             url: '/EquipmentManage/Equipment/GetTreeGridJson' + (!queryJson ? '' : '?keyword=' + queryJson),
             sqlkey: 'F_Id',//数据库主键
             tree: {
                 iconIndex: 2,           // 折叠图标显示在第几列
                 isPidData: true,        // 是否是id、pid形式数据
                 idName: 'F_Id',  // id字段名称
                 pidName: 'F_ParentId',     // pid字段名称
                 arrowType: 'arrow2',
                 getIcon: 'ew-tree-icon-style2',
             },
             cols: [[
                 { type: "checkbox", width: 50 },
                { field: 'F_Id', title: 'Id', width: 100,hide:true },
                {
                    field: 'F_EqpType', title: '设备类型', width: 120,
                    templet: function (d) {
                        return top.clients.dataItems["Mes_EqpType"][d.F_EqpType] == null ? "" : top.clients.dataItems["Mes_EqpType"][d.F_EqpType];
                    }
                },
                {
                    field: 'F_EqpUse', title: '设备用途', width: 120,
                    templet: function (d) {
                        return top.clients.dataItems["Mes_EqpUse"][d.F_EqpUse] == null ? "" : top.clients.dataItems["Mes_EqpUse"][d.F_EqpUse];
                    }
                },
                 { field: 'F_EqpName', title: '设备名称', width: 200 },
                 { field: 'F_BatchPrefix', title: '批号前缀', width: 120 },
                 {
                     field: 'F_BatchType', title: '批号类型', width: 120,
                     templet: function (d) {
                         if (d.F_BatchType==0) {
                             return "年月日班";

                         }
                         else if (d.F_BatchType == 1){
                             return "年月日时分秒";
                         }
                     }
                 },

                 {
                     field: 'F_EqpState', title: '设备状态', width: 120, sort: true,
                     templet: function (d) {
                         return top.clients.dataItems["Mes_EqpState"][d.F_EqpState] == null ? "" : top.clients.dataItems["Mes_EqpState"][d.F_EqpState];
                     }
                 },
                { field: 'F_DieNum', title: '模具编号', width: 110, filter: true,hide:true },
                { field: 'F_MoldingNum', title: '模块数', width: 95, filter: true,hide:true },
                 {
                     field: 'F_EqpOwner', title: '财产所属', width: 120,
                     templet: function (d) {
                         return top.clients.dataItems["Mes_EqpOwner"][d.F_EqpOwner] == null ? "" : top.clients.dataItems["Mes_EqpOwner"][d.F_EqpOwner];

                     }
                 },
                 { field: 'F_CompanyName', title: '所属公司', width: 120 },
                 { field: 'F_PlanUserNum', title: '预计使用次数', width: 120, hide: true },
                 { field: 'F_UsedNum', title: '已使用次数', width: 120, hide: true },
                 {
                     field: 'F_MaintainType', title: '保养周期类型', width: 120, hide: true,
                     templet: function (d) {
                         return top.clients.dataItems["Mes_MaintainType"][d.F_MaintainType] == null ? "" : top.clients.dataItems["Mes_MaintainType"][d.F_MaintainType];
                     }
                 },
                 { field: 'F_MaintainNum', title: '保养周期', width: 120, hide: true },
                 {
                     field: 'F_CreatorTime', title: '创建时间', width: 160, sort: true
                 },
                 {
                     field: 'F_IsMaintain', title: '保养', width: 80, sort: true,
                     templet: function (d) {
                         if (d.F_IsMaintain == true) {
                             return "<span class='layui-btn layui-btn-normal layui-btn-xs'>是</span>";
                         } else {
                             return "<span class='layui-btn layui-btn-warm layui-btn-xs'>否</span>";
                         }
                     }
                 },
                 {
                     field: 'F_IsOtherEqp', title: '加载', width: 80, sort: true,
                     templet: function (d) {
                         if (d.F_IsOtherEqp == true) {
                             return "<span class='layui-btn layui-btn-normal layui-btn-xs'>是</span>";
                         } else {
                             return "<span class='layui-btn layui-btn-warm layui-btn-xs'>否</span>";
                         }
                     }
                 },
                 {
                     field: 'F_EnabledMark', title: '状态', width: 80, sort: true,
                     templet: function (d) {
                         if (d.F_EnabledMark == true) {
                             return "<span class='layui-btn layui-btn-normal layui-btn-xs'>有效</span>";
                         } else {
                             return "<span class='layui-btn layui-btn-warm layui-btn-xs'>无效</span>";
                         }
                     }
                 },
                 { field: 'F_Description', title: '设备描述', minWidth: 120 },
                 { title: '操作', width: 210, toolbar: '#currentTableBar', align: "center", fixed: 'right' }//插件没有fixed参数
             ]]
         });
         // 监听搜索操作
         form.on('submit(data-search-btn)', function (data) {
             var queryJson = data.field.txt_keyword;
             //执行搜索重载
             common.reloadtreetable(rendertree, {
                 where: { keyword: queryJson },
             });
             return false;
         });
         wcLoading.close();
         //行点击事件监听，控制按钮显示
         var oneList = ["NF-edit", "NF-details", "NF-banding", "NF-materialbanding"];//选择1条显示
         var moreList = ["NF-delete", "NF-print"];//选择多条显示
         common.treeTableRowClick("checkbox", rendertree, "currentTableId", oneList, moreList);
         //toolbar监听事件
         treeTable.on('toolbar(currentTableId)', function (obj) {
             var data = rendertree.checkStatus(false);
             if (obj.event === 'add') {  // 监听添加操作s
                 common.modalOpen({
                     title: "添加界面",
                     url: "/EquipmentManage/Equipment/Form",
                     width: "500px",
                     height: "600px",
                 });
             }
             else if (obj.event === 'delete') {
                 if (data.length == 0) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 if (data[0].F_EqpState != 0) {
                     common.modalMsg("设备使用中，无法操作", "warning");
                     return false;
                 }
                 var ids = [];
                 for (var i = 0; i < data.length; i++) {
                     ids.push(data[i].F_Id);
                 }
                 common.deleteForm({
                     url: "/EquipmentManage/Equipment/DeleteForm",
                     param: { keyValue: ids.join(',') },
                     success: function () {
                         common.reload('data-search-btn');
                         entity = null;
                     }
                 });
             }
             else if (obj.event === 'edit') {
                 if (data.length == 0) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 common.modalOpen({
                     title: "编辑界面",
                     url: "/EquipmentManage/Equipment/Form?keyValue=" + data[0].F_Id,
                     width: "500px",
                     height: "600px",
                 });
             }
             else if (obj.event === 'details') {
                 if (data.length == 0) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 common.modalOpen({
                     title: "查看界面",
                     url: "/EquipmentManage/Equipment/Details?keyValue=" + data[0].F_Id,
                     width: "500px",
                     height: "600px",
                     btn: []
                 });
             }
             else if (obj.event === 'materialbanding') {
                 if (data.length == 0) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 if (data[0].F_ParentId != "0") {
                     common.modalMsg("子设备无需绑定", "warning");
                     return false;
                 }
                 if (data[0].F_EqpType != 0) {
                     common.modalMsg("固定设备才能绑定", "warning");
                     return false;
                 }
                 common.modalOpen({
                     title: "物料绑定",
                     url: "/EquipmentManage/Equipment/MaterialForm?keyValue=" + data[0].F_Id,
                     width: "780px",
                     height: "650px",
                 });
             }
             else if (obj.event === 'print') {
                 if (data.length == 0) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 if (top.websocket == null || top.websocket.readyState == 3) {
                     common.modalMsg("打印服务未开启", "warning");
                     return false;
                 }
                 common.modalConfirm("注：您确定要打印选中这些数据吗？", function (r) {
                     if (r) {
                         var ids = [];
                         var json = {};
                         json.cmd = "print";
                         json.requestId = uuid();
                         json.data = {};
                         json.data.printIniInfo = {};
                         json.data.printIniInfo.filePath = window.document.location.origin + top.clients.printTemplates["二维码编号名称模板"];
                         json.data.printIniInfo.realName = "二维码编号名称模板";
                         json.data.printIniInfo.printType = 1;
                         json.data.printIniInfo.printName = "";
                         json.data.printIniInfo.landscape = true;
                         json.data.printIniInfo.paperSize = "";
                         json.data.printIniInfo.duplex = "";
                         json.data.data = [];
                         for (var i = 0; i < data.length; i++) {
                             var temp = {};
                             temp.barId = data[i].F_Id;
                             temp.code = "设备名称";
                             temp.name = data[i].F_EqpName;
                             json.data.data.push(temp);
                         }
                         top.sendWSPush(json);
                     }
                 });
             }
             else if (obj.event === 'banding') {
                 if (data.length == 0) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 if (data[0].F_ParentId != "0") {
                     common.modalMsg("子设备无需绑定", "warning");
                     return false;
                 }
                if (data[0].F_EqpType != 0) {
                    common.modalMsg("固定设备才能绑定", "warning");
                    return false;
                }
                 common.openNewTabByIframe({
                     title: "区域绑定",
                     href: "/EquipmentManage/EqpArea/Index?keyValue=" + data[0].F_Id,
                 });
             }
             else if (obj.event === 'TABLE_SEARCH') {
                 var _that = $("#searchField");
                 if (_that.hasClass("layui-hide")) {
                     _that.removeClass('layui-hide');
                 } else {
                     _that.addClass('layui-hide');
                 }
             }
             return false;
         });
         //toolbar监听事件
         treeTable.on('tool(currentTableId)', function (obj) {
             if (obj.event === 'delete') {
                 if (obj.data.F_EqpUse == 7) {
                     common.modalMsg("模具请从模具管理操作", "warning");
                     return false;
                 }
                 common.deleteForm({
                     url: "/EquipmentManage/Equipment/DeleteForm",
                     param: { keyValue: obj.data.F_Id },
                     success: function () {
                         obj.del();
                     }
                 });
             }
             else if (obj.event === 'edit') {
                 common.modalOpen({
                     title: "编辑界面",
                     url: "/EquipmentManage/Equipment/Form?keyValue=" + obj.data.F_Id,
                     width: "500px",
                     height: "600px",
                 });
             }
             else if (obj.event === 'details') {
                 common.modalOpen({
                     title: "查看界面",
                     url: "/EquipmentManage/Equipment/Details?keyValue=" + obj.data.F_Id,
                     width: "500px",
                     height: "600px",
                     btn: []
                 });
             }
             else if (obj.event === 'banding') {
                 if (obj.data.F_ParentId != "0") {
                     common.modalMsg("子设备无需绑定", "warning");
                     return false;
                 }
                if (data[0].F_EqpType != 0) {
                    common.modalMsg("固定设备才能绑定", "warning");
                    return false;
                }
                 common.openNewTabByIframe({
                     title: "区域绑定",
                     href: "/EquipmentManage/EqpArea/Index?keyValue=" + obj.data.F_Id,
                 });
             }
             else if (obj.event === 'materialbanding') {
                 if (obj.data.F_ParentId != "0") {
                     common.modalMsg("子设备无需绑定", "warning");
                     return false;
                 }
                if (data[0].F_EqpType != 0) {
                    common.modalMsg("固定设备才能绑定", "warning");
                    return false;
                }
                 common.modalOpen({
                     title: "物料绑定",
                     url: "/EquipmentManage/Equipment/MaterialForm?keyValue=" + obj.data.F_Id,
                     width: "780px",
                     height: "650px",
                 });
             }
             return false;
         });
     });
 </script>
